home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / infoserv / gopher / Gopher_Conference_94 / Papers / SafeGopher.Z / SafeGopher
Encoding:
Text File  |  1994-04-20  |  11.1 KB  |  330 lines

  1. Guide to Safe Gophering
  2.  
  3. Paul Lindner
  4.  
  5.  
  6.  
  7. In any software product as large and complex as gopher there is the possibility of security holes. In this paper we'll show 
  8. you what they are and how to run a secure gopher server, gopher client, and gopher public access system.
  9.  
  10.  
  11.  
  12. April 18, 1994
  13.  
  14. 1.0    Introduction
  15.  
  16. Gopher has had its small share of security problems. The 
  17. University of Minnesota, in conjunction with CERT and 
  18. other computer security agencies attempts to keep the 
  19. Gopher software as secure as it possibly can. 
  20.  
  21. Now that the gopher software is installed on thousands of 
  22. sites it is imperative that all holes be documented and 
  23. fixed. We believe that release 1.13 and 2.013 are free of 
  24. security holes and that you should upgrade to these 
  25. releases as soon as possible.
  26.  
  27. We make no claims as the security or insecurity of other 
  28. software. This paper only applies to the Unix/VMS 
  29. Gopher Software released by the University of Minnesota.
  30.  
  31. 2.0     The Origin of Holes
  32.  
  33. There are a few programming practices and design deci-
  34. sions that have caused most of the holes in gopher soft-
  35. ware. These practices pervade other software packages 
  36. too.
  37.  
  38. 2.1    Use of software routines to insure security.
  39.  
  40. The most popular method of maintaining a secure environ-
  41. ment is to use the chroot() system call to change the loca-
  42. tion of the / directory to a subdirectory. This is the method 
  43. used by most FTP servers. Consider the following code 
  44. snippet: 
  45.  
  46.  chroot("/usr/local/gopher-data");
  47.  
  48. This code causes the program to instantly think
  49.  
  50. /usr/local/gopher-data
  51.  
  52. is the slash directory. Thus if you try to access /etc/passwd 
  53. you will, in fact, be attempting to access
  54.  
  55. /usr/local/gopher-data/etc/passwd
  56.  
  57. There are a couple of problems with this scheme however. 
  58. The first is that you need root privileges to use this system 
  59. call. Also, sometimes you want to access files that aren't in 
  60. your gopher-data directory. For instance you might want 
  61. to make a symbolic link to your manual pages like this:
  62.  
  63.  ln -s /usr/man /usr/local/gopher-data/manual-pages
  64.  
  65. The solution to both of these problems was contributed by 
  66. John Sellins from the University of Waterloo.
  67.  
  68. Instead of relying on the chroot() system call, a suite of 
  69. software routines were written to insure that all requests 
  70. are legitimate. The routines strip out all occurrences of `..' 
  71. in gopher requests and append the server data directory to 
  72. certain requests. If these checks weren't in place a cracker 
  73. could do this:
  74.  
  75.  0/../../../../../../../../../../etc/passwd
  76.  
  77. This request would retrieve the password file of the system 
  78. running the gopher server if it wasn't for the dot stripping 
  79. routines.
  80.  
  81. Our example of a symbolic link works however, since 
  82. there aren't any `..' character strings in the request.
  83.  
  84. As we'll see later, bugs and oversights in this section of 
  85. code have caused security holes.
  86.  
  87. 2.2    Use of Dangerous Routines in the Server 
  88. and Client
  89.  
  90. The server and client use two highly dangerous routines to 
  91. implement portions of the code. These calls are system() 
  92. and popen(). The server uses this code to decompress files 
  93. on the fly and run shell scripts to perform functions not 
  94. implemented in the server. The client uses these routines 
  95. to execute `helper' applications to send email, invoke tele-
  96. communications download protocols and display many 
  97. data types.
  98.  
  99. The problem with both of these calls is that they use the 
  100. shell `sh' to evaluate the expression sent to them. The shell 
  101. has a very extensive feature set that makes it difficult to 
  102. ensure security through software routines. It's possible for 
  103. a malicious user to exploit these weaknesses to actually 
  104. run commands on the server. For instance the gopher 
  105. server has a special notation for running an external shell 
  106. script. Here's an example:
  107.  
  108.  exec:arg1 arg2:/bin/legisearch
  109.  
  110. In this case the server executes:
  111.  
  112.  popen("/bin/legisearch arg1 arg2");
  113.  
  114. which in turn executes:
  115.  
  116.  sh -c "/bin/legisearch arg1 arg2"
  117.  
  118. In earlier versions of the server a malicious user could 
  119. send the following command to a server running with the 
  120. `-c' (non-chroot) option: 
  121.  
  122.  exec:arg1 ;cat /etc/passwd:/bin/legisearch
  123.  
  124. The server then would then execute:
  125.  
  126.  sh -c "/bin/legisearch arg1 ;cat /etc/passwd"
  127.  
  128. The semicolon (;) tells the shell to execute a second com-
  129. mand and add the results to that of the first. In this case the 
  130. command prints out the contents of the Unix password 
  131. file.
  132.  
  133. This problem will only occur if you have shell scripts on 
  134. your server (the software will not execute non-existent 
  135. shell scripts.) If you're using the default chroot() mode a 
  136. cracker won't be able to get at files outside of the gopher 
  137. directory tree. However, they could still wreak major dam-
  138. age to your gopher data.
  139.  
  140. This problem of hidden code execution plagued earlier 
  141. versions of the client as well. The Gopher client allows 
  142. connections to telnet sites by launching the telnet com-
  143. mand with the name of a host. It does this by using the sys-
  144. tem() system call like this:
  145.  
  146.  system("telnet pubinfo.ais.umn.edu");
  147.  
  148. However if an unscrupulous server administrator created a 
  149. bogus telnet item with a hostname like this:
  150.  
  151.  "pubinfo.ais.umn.edu;echo + >.rhosts"
  152.  
  153. This would cause the .rhosts file of the person using the 
  154. client to be compromised when they selected the item. 
  155. Gopher links like this are `telnet bombs' just waiting to be 
  156. opened, much like physical mail bombs.
  157.  
  158. Starting with release 2.0.12 we've started replacing these 
  159. routines with more general secure code that does not use 
  160. the shell. So far we've converted most of the client side 
  161. and some of the server calls. Eventually we will be rid of 
  162. this problem altogether.
  163.  
  164. 3.0     Known Holes
  165.  
  166. Here is a list of the known holes in gopher and gopherd for 
  167. Unix system. It is probably not complete. 
  168.  
  169. ╖    All releases between 0.9 and 1.12 and 2.0 to 2.04 may 
  170. allow executing external commands with the exec: 
  171. facility.
  172.  
  173. ╖    All releases between 2.0 and 2.012 and before 1.13 
  174. may allow `telnet bombs'.
  175.  
  176. ╖    Releases before 2.0.12 had dedot routines that could be 
  177. tricked with the right combination of quotes and dots.
  178.  
  179. 4.0     Known Bad Practices
  180.  
  181. These aren't holes really, but they are things that people do 
  182. that could prove very, very dangerous..
  183.  
  184. Some sites allow simultaneous ftp and gopher access to 
  185. the same set of files. Often a directory will be writable for 
  186. uploads for ftp users. If the execute bit is turned on for 
  187. uploads the cracker could upload shell scripts to the server, 
  188. which could then be activated by a gopher client.
  189.  
  190. 5.0    Insuring Security of the Gopher 
  191. Server
  192.  
  193. Even with the potential for security holes it is still possible 
  194. to run a secure gopher server. The following steps are 
  195. insurance against future security holes.
  196.  
  197. The safest thing in any circumstances is to not run the 
  198. server at all. If you are very security conscious you may 
  199. not want to trust your data to software that doesn't come 
  200. with a warranty.
  201.  
  202. However this is short sited at best. There are a number of 
  203. techniques to make your gopher server secure.
  204.  
  205. ╖    Avoid the chroot() (-c) option if you can. This is per-
  206. haps the most dangerous portion of the gopher code. 
  207. It's been gone over with a fine tooth comb, but there's 
  208. no guarantee that we've closed every loophole.
  209.  
  210. ╖    Always, always, always run the server as a non-root 
  211. user i.d. The server has a -u parameter to set the user-
  212. name. Use it! Any damage that a user can cause can be 
  213. minimized by running as a non privileged user.
  214.  
  215. ╖    Be careful with shell scripts. The gopher server can't 
  216. save you from shooting yourself in the foot by using a 
  217. poorly written, insecure shell script. 
  218.  
  219. ╖    Always log your transactions! Use the -l option of 
  220. gopherd to specify a log file like this.
  221.  
  222.  -l /usr/adm/gopherlog
  223.  
  224. This will give you an audit trail in case anything hap-
  225. pens. It also gives you a way to find anomalies in 
  226. access. A log analyzer will be able to tell you if you're 
  227. receiving a disproportionate number of connections 
  228. from certain sites
  229.  
  230. ╖    If your server contains sensitive information you may 
  231. want to use the ip/hostname security option of the 
  232. server. This is done by using `access:' lines in your 
  233. gopherd.conf configuration file.
  234.  
  235. The following lines will allow only hosts from the Uni-
  236. versity of Minnesota to access your server. Note that 
  237. this style of security has some obscure holes. If your 
  238. DNS server is compromised, then so is your gopher 
  239. server if it uses this form of authentication.
  240.  
  241.  access: default !read,!browse,!search,!ftp
  242.  
  243.  access: .umn.edu read,browse,search,ftp
  244.  
  245. ╖    Consider executing your scripts with `taintperl'. This 
  246. version of perl makes sure that you never use user 
  247. input to execute a command on your system.
  248.  
  249. 6.0     Insuring the Security of Your Client
  250.  
  251. The client is less problematic that the server, but it still has 
  252. it's own problems.
  253.  
  254. ╖    Upgrade to 2.013 or higher. Earlier versions could 
  255. potentially execute a `telnet bomb'. If you read the 
  256. warning screen you'll probably notice it, but you could 
  257. easily miss it.
  258.  
  259. ╖    Certain file types are inherently insecure. You should 
  260. trust the source of postscript and Microsoft Word docu-
  261. ments before viewing them. Both systems can execute 
  262. system macros that could alter data and files on your 
  263. system. This is not a gopher problem, but a general 
  264. information retrieval problem. Other file formats can 
  265. potentially cause the same problems.
  266.  
  267. 7.0     Insuring the Security of Your Public 
  268. Access Client
  269.  
  270. A public access client allows people to connect to the 
  271. internet, (often without a password) and use a gopher cli-
  272. ent. This allows dial up users and those without the 
  273. resources to run a gopher client on their own system 
  274. access to the gopher network. A public access client can 
  275. be an enormous security risk if not installed properly. The 
  276. following steps should give you a secure public access cli-
  277. ent, but again, we make no guarantees.
  278.  
  279. The first step is to create the home directory of the for the 
  280. guest account. This directory should not be writable nor 
  281. owned by the guest account.
  282.  
  283. In this directory you will want to place a shell script that 
  284. will start the gopher client automatically. Here is an exam-
  285. ple:
  286.  
  287. #!/bin/sh 
  288.  
  289. GHOME=/home/hafnhaf/gopher
  290.  
  291. USER=`whoami` export $USER
  292.  
  293. eval `tset - -s -m "network:?vt100" -m 
  294. "unknown:?vt100" -m "dumb:?vt100" -m 
  295. ":?vt100"` 
  296.  
  297. echo "I think you're on a $TERM terminal"
  298.  
  299. sleep 3 
  300.  
  301. PATH=$GHOME/bin
  302.  
  303. export PATH
  304.  
  305. exec /home/hafnhaf/gopher/gopher -s $GHOST 70
  306.  
  307. Note that we set the path to a bin directory inside of the 
  308. guest account directory. We want to insure that only pro-
  309. grams inside of this directory are run. The reason we do 
  310. this is that many programs allow you to get to a shell, like 
  311. telnet, tn3270, less, more and many others. You should put 
  312. secure versions of these programs in the bin directory 
  313. inside the guest directory.
  314.  
  315. Also note that we use the -s option for gopher. This 
  316. invokes the `secure' option of the client. In this mode the 
  317. client won't let you save or print.
  318.  
  319. Finally you can create the guest account. Make sure that 
  320. the shell is specified as the script. Don't put /bin/csh or /
  321. bin/sh for the shell. Here's an example entry for a guest 
  322. account:
  323.  
  324.  gopher::10000:10:Public Access Account:/home/
  325. gopher:/home/gopher/Startup
  326.  
  327. Don't forget to honor the warnings for the regular client as 
  328. well. On public access systems people will actually try to 
  329. run telnet bombs.
  330.